package com.fishery.processing.mapper;

import com.fishery.processing.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ${author}
 * @since 2021-01-14
 */
public interface ProductMapper extends BaseMapper<Product> {

    //获取使用了指定工艺的加工产品
    @Select("SELECT pp.* FROM t_processing_product pp INNER JOIN t_processing_product_craft ppc WHERE ppc.craft_id = #{craftId} AND pp.id = ppc.product_id;")
    public List<Product> findProductsOfCraft(@Param("craftId") String craftId);

    //删除加工厂所有产品的连接表信息
    @Delete("DELETE FROM t_processing_product_craft WHERE product_id IN (SELECT id FROM t_processing_product WHERE processing_factory_id = #{factoryId});")
    public int removeProductOfFactory(@Param("factoryId") String factoryId);

    @Select("SELECT product_name FROM t_processing_product WHERE id = #{productId}")
    public String getProductNameById(String productId);
}
